{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "L=6; R=10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "3\n",
      "1\n",
      "2\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "for i in range(L,R+1):\n",
    "    print(bin(i).count(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def isPrime(self, num):\n",
    "    if num > 1:\n",
    "       # check for factors\n",
    "       for i in range(2,num):\n",
    "            if (num % i) == 0:\n",
    "                return False\n",
    "       return True\n",
    "\n",
    "    # if input number is less than\n",
    "    # or equal to 1, it is not prime\n",
    "    else:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isPrime(1, 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation\n",
    "\n",
    "\n",
    "Runtime: 352 ms, faster than 59.88% of Python3 online submissions for Prime Number of Set Bits in Binary Representation.\n",
    "Memory Usage: 14.3 MB, less than 60.08% of Python3 online submissions for Prime Number of Set Bits in Binary Representation.\n",
    "\n",
    "\n",
    "```python\n",
    "class Solution:\n",
    "    def countPrimeSetBits(self, L: int, R: int) -> int:\n",
    "        counting = 0\n",
    "        for i in range(L,R+1):\n",
    "            if self.isPrime(bin(i).count(\"1\")):\n",
    "                counting += 1\n",
    "        return counting \n",
    "    \n",
    "    def isPrime(self, num):\n",
    "        if num > 1:\n",
    "            for i in range(2,num):\n",
    "                if (num % i) == 0:\n",
    "                    return False\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
